﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
namespace DongFangGuoKai.TaskPlatform.Commn.ApiModule
{
    public class SH1Helper
    {
        /// <summary>
        /// Sha1加密
        /// </summary>
        /// <param name="input">加密字符串 </param>
        /// <returns></returns>
        public static string ComputeSHA1(string input)
        {
            using (SHA1Managed sha1 = new SHA1Managed())
            {
                byte[] inputBytes = Encoding.UTF8.GetBytes(input);
                byte[] hashBytes = sha1.ComputeHash(inputBytes);

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < hashBytes.Length; i++)
                {
                    sb.Append(hashBytes[i].ToString("x2")); // Convert byte to hexadecimal string
                }
                return sb.ToString();
            }
        }


        /// <summary>
        ///通过总秒数获取有效时间 
        /// </summary>
        /// <param name="seconds">总秒数</param>
        /// <returns></returns>
        public static DateTimeOffset FromUnixTimeSeconds(long seconds)
        {
            return DateTimeOffset.FromUnixTimeSeconds(seconds);
        }

        /// <summary>
        /// 通过总毫秒数获取有效时间
        /// </summary>
        /// <param name="milliseconds">总毫秒数</param>
        /// <returns></returns>
        public static DateTimeOffset FromUnixTimeMilliseconds(long milliseconds)
        {
            return DateTimeOffset.FromUnixTimeMilliseconds(milliseconds);
        }
    }
}
